local ui = require "JSON"
local bb = require("badboy")
require "function"
bb.loadutilslib()
init("0", 1); --以当前应用 Home 键在右边初始化
--主ui界面
local w_,h_ = getScreenSize() --w < h
local h = w_
local w = h_

if w/h == 1280/720 then
	setScreenScale(720,1280,0)
else
	toast("暂不支持此分辨率，不能保证脚本正常运行")
end

local content, err = getCloudContent("wangzherongyao", "2757EECDA00C9D5E", "没有正确获取到公告信息")

ui:new(w-80,h-80,"","下一步","不玩了","save_最新.dat")
local p = ui:newPage("基本设置")
--------------------
p:newLine()
p:addLebel(4.3,0.5,"任务设置","18","left","")
p:newLine()
p:addCheckBoxGroup(0.9,9.8,1,"任务设置","0@1@2@3","铭文抽奖","战队签到","冒险模式","人机对战")
p:newLine()
p:addLebel(9,2,content,"18","left","255,0,0")

local p = ui:newPage("冒险模式")
p:newLine()
p:addLebel(4.3,0.5,"冒险设置","18","left","")
p:newLine()
p:addCheckBoxGroup(0.9,9.8,1,"模式选择","0@1","挑战","六国远征")
p:newLine()
p:addLebel(4.3,0.5,"武道大会英雄设置","18","left","")
p:newLine()
p:addLebel(1,1.2,"第一位","18","left","")
p:addComboBox(0.9,2.8,1.1,"武道大会英雄_类型_1","0","全部","坦克","战士","刺客","法师","射手","辅助")
p:addComboBox(0.9,2.8,1.1,"武道大会英雄_行数_1","0","1","2","3","4")
p:addComboBox(0.9,2.8,1.1,"武道大会英雄_个数_1","0","1","2","3", "4","5","6","7","8")
p:newLine()
p:addLebel(1,1.2,"第二位","18","left","")
p:addComboBox(0.9,2.8,1.1,"武道大会英雄_类型_2","0","全部","坦克","战士","刺客","法师","射手","辅助")
p:addComboBox(0.9,2.8,1.1,"武道大会英雄_行数_2","0","1","2","3","4")
p:addComboBox(0.9,2.8,1.1,"武道大会英雄_个数_2","1","1","2","3", "4","5","6","7","8")
p:newLine()
p:addLebel(1,1.2,"第三位","18","left","")
p:addComboBox(0.9,2.8,1.1,"武道大会英雄_类型_3","0","全部","坦克","战士","刺客","法师","射手","辅助")
p:addComboBox(0.9,2.8,1.1,"武道大会英雄_行数_3","0","1","2","3","4")
p:addComboBox(0.9,2.8,1.1,"武道大会英雄_个数_3","2","1","2","3", "4","5","6","7","8")
p:newLine()
p:addLebel(9,0.5,"PS:自己保证选择的英雄不是体验卡，目前体验卡先不处理","18","left","255,0,0")
p:newLine()
p:addLebel(4.3,0.5,"挑战英雄设置","18","left","")
p:newLine()
p:addLebel(1,1.2,"关卡选择","18","left","")
p:addComboBox(0.9,4.26,1.1,"挑战关卡","1","魔女回忆","通天塔")
p:addComboBox(0.9,4.26,1.1,"挑战难度","2","普通","精英","大师")
p:newLine()
p:addLebel(1,1.2,"第一位","18","left","")
p:addComboBox(0.9,2.8,1.1,"挑战英雄_类型_1","0","全部","坦克","战士","刺客","法师","射手","辅助")
p:addComboBox(0.9,2.8,1.1,"挑战英雄_行数_1","0","1","2","3","4")
p:addComboBox(0.9,2.8,1.1,"挑战英雄_个数_1","0","1","2","3", "4","5","6","7","8")
p:newLine()
p:addLebel(1,1.2,"第二位","18","left","")
p:addComboBox(0.9,2.8,1.1,"挑战英雄_类型_2","0","全部","坦克","战士","刺客","法师","射手","辅助")
p:addComboBox(0.9,2.8,1.1,"挑战英雄_行数_2","0","1","2","3","4")
p:addComboBox(0.9,2.8,1.1,"挑战英雄_个数_2","1","1","2","3", "4","5","6","7","8")
p:newLine()
p:addLebel(1,1.2,"第三位","18","left","")
p:addComboBox(0.9,2.8,1.1,"挑战英雄_类型_3","0","全部","坦克","战士","刺客","法师","射手","辅助")
p:addComboBox(0.9,2.8,1.1,"挑战英雄_行数_3","0","1","2","3","4")
p:addComboBox(0.9,2.8,1.1,"挑战英雄_个数_3","2","1","2","3", "4","5","6","7","8")
p:newLine()



local p = ui:newPage("人机对战")
p:newLine()
p:addLebel(4.3,0.5,"英雄设置","18","left","")
p:newLine()
p:addComboBox(0.9,3.1,1.1,"人机对战英雄_类型_1","0","全部","坦克","战士","刺客","法师","射手","辅助")
p:addComboBox(0.9,3.1,1.1,"人机对战英雄_行数_1","0","1","2","3","4")
p:addComboBox(0.9,3.1,1.1,"人机对战英雄_个数_1","0","1","2","3", "4","5","6","7","8")
p:newLine()


function quickTap(x,y)
	touchDown(1, x, y)
	mSleep(50)
	touchUp(1, x, y)
end

function 进入挑战冒险()
	showHUD(id,"冒险模式==>挑战进行中",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
	
	while true do
		mSleep(200)
		--查找右上角自动按钮
		x, y = findColor({1162, 4, 1227, 55},
			"0|0|0x2db0d8,8|-1|0x29acdd,16|7|0x1e9ccb,25|-1|0x2fadd5,32|-1|0x2fa9d9",
			95, 0, 0, 0)
		if x > -1 then
			quickTap(x,y)
		end
		
		--挑战失败返回
		x, y = findColor({542, 626, 741, 682},
			"0|0|0xe59a1f,12|-2|0xffffff,19|-5|0xffffff,36|-2|0xe79d19",
			95, 0, 0, 0)
		if x > -1 then
			quickTap(x,y)
			--点击返回到冒险界面
			while true do
				mSleep(125)
				x, y = findColor({19, 5, 122, 74},
					"0|0|0x10c9df,10|0|0x0ed0e5,37|24|0x28c1e8",
					95, 0, 0, 0)
				if x > -1 then
					quickTap(x,y)
					break
				end
			end
		end
		
		--查找跳过按钮
		x, y = findColor({1129, 24, 1256, 63},
			"0|0|0x3ab1e2,12|23|0x319fde,57|7|0x3395d6",
			95, 0, 0, 0)
		if x > -1 then
			quickTap(x,y)
			
		end
		
		--点击屏幕继续
		x, y = findColor({523, 655, 754, 706},
			"0|0|0xffffff,8|-8|0xffffff,18|0|0xffffff,21|0|0x285884",
			95, 0, 0, 0)
		if x > -1 then
			print("点击屏幕继续")
			quickTap(x,y)
			mSleep(3000)
		end
		
		--闯关
		x, y = findColor({903, 584, 1061, 639},
			"0|0|0xe59e26,10|3|0xffffff,32|0|0xffffff,44|1|0xe6a026",
			95, 0, 0, 0)
		if x > -1 then
			quickTap(x,y)
			
		end
		
		--再次挑战
		x1, y1 = findColor({987, 625, 1139, 686},
			"0|0|0xde9326,6|0|0xffffff,16|1|0xffffff,33|-1|0xe6a227",
			95, 0, 0, 0)
		if x1 > -1 then
			
			--查找是否金币已满
			local 金币是否已满 = false
			for i=0,10,1 do
				mSleep(125)
				print("金币是否已满")
				
				x, y = findColor({906, 373, 1037, 440},
					"0|0|0xeeecce,6|0|0xeeecce,15|0|0xeeecce,34|-3|0xeeecce,36|-9|0xeeecce,44|-22|0xeeecce,53|-18|0xeeecce,55|-9|0xeeecce,54|3|0xeeecce,52|10|0xeeecce,44|13|0xeeecce",
					95, 0, 0, 0)
				if x > -1 then
					print("金币已满")
					金币是否已满 = true
					break
				end
			end
			
			if 金币是否已满 then
				quickTap(873,662)
				mSleep(2000)
				while true do
					mSleep(125)
					print("金币已满")
					
					x, y = findColor({14, 4, 120, 71},
						"0|0|0x0fc8e0,4|0|0x0ecde3,24|-2|0x0fcfe3,14|28|0x1fc8ed,36|19|0x2abadd",
						95, 0, 0, 0)
					if x > -1 then
						quickTap(x,y)
						break
					end
				end
				break
				
			else
				print("金币未满")
				
				quickTap(x1,y1)
				mSleep(1000)
			end
		end
		
	end
end

function 武道大会()
	
	while true do
		mSleep(200)
		showHUD(id,"武道大会挑战中",12,"0xFFFFFFFF","0x40969696",0,254,685,685,34)      --显示HUD内容
		--查找右上角自动按钮
		x, y = findColor({1167, 0, 1221, 54},
			"0|0|0x2db0d5,17|7|0x1e9ccb,32|-1|0x29afdf",
			95, 0, 0, 0)
		if x > -1 then
			print("切换至自动模式")
			quickTap(x,y)
		end
		
		
		
		--继续按钮
		x, y = findColor({539, 613, 740, 695},
			"0|0|0x377cbc,38|-8|0x3ba7d8,77|-1|0xffffff,106|-10|0xffffff,119|-10|0x37a3d4,107|6|0xffffff",
			95, 0, 0, 0)
		if x > -1 then
			print("继续按钮")
			
			quickTap(x,y)
			mSleep(5000)
			
			--判断当前界面
			local 是否挑战失败 = false
			for i=0,20,1 do
				mSleep(200)
				print("判断当前界面")
				--判断是否有重置，如果有的话，就是挑战失败了
				x, y = findColor({753, 226, 843, 257},
					"0|0|0xffffff,-7|6|0xfdfefe,-9|6|0x3493d3,16|9|0xffffff,34|7|0x3589ce",
					95, 0, 0, 0)
				if x > -1 then
					是否挑战失败 = true
					print("判断挑战失败")
					
					break
				end
			end
			
			if 是否挑战失败 then
				--如果挑战失败，就返回上一层
				print("挑战失败，返回上一层")
				
				quickTap(77,34)
				mSleep(4000)
				
				quickTap(1060,487)
				mSleep(2000)
				break
			else
				--如果挑战成功，继续挑战
				print("挑战成功，继续挑战")
				
				local 是否弹出挑战按钮 = false
				for i=0,20,1 do
					mSleep(125)
					x, y = findColor({531, 520, 1120, 580},
						"0|0|0xe8a21d,16|-6|0xeba81d,18|21|0xe6961d,52|8|0xe69619",
						95, 0, 0, 0)
					if x > -1 then
						--查找到挑战按钮
						showHUD(id,"冒险模式==>开始挑战",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
						
						quickTap(x,y)
						break
					end
				end
				
				
				
				for i=0,20,1 do
					--点击挑战按钮
					mSleep(125)
					x, y = findColor({743, 233, 990, 339},
						"0|0|0xe6a229,8|1|0xffffff,19|0|0xffffff,24|0|0xffffff",
						95, 0, 0, 0)
					if x > -1 then
						是否弹出挑战按钮 = true
						quickTap(x,y)
						break
					end
				end
				
				--冷却或者挑战完了
				if 是否弹出挑战按钮 == false then
					showHUD(id,"冒险模式==>暂时不能挑战，返回",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
					
					mSleep(500)
					quickTap(71,40)
					break
				end
				mSleep(1000)
				--先清空所以上阵英雄
				showHUD(id,"冒险模式==>检测并删除已上阵英雄",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
				
				for i=0,10,1 do
					mSleep(125)
					x, y = findColor({1099, 48, 1249, 560},
						"0|0|0xfeffff,1|-8|0x9e0e25,0|9|0x7f0816,-10|0|0x8b0b1c,10|-1|0x8d0c1e",
						95, 0, 0, 0)
					if x > -1 then
						quickTap(x,y)
						mSleep(500)
					end
				end
				
				--按用户配置选择上阵英雄
				showHUD(id,"冒险模式==>武道大会英雄选择",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
				mSleep(1000)
				quickTap(305,365) --展开英雄
				mSleep(1500)
				local 武道大会英雄_类型_1 = result["武道大会英雄_类型_1"]
				local 武道大会英雄_行数_1 = result["武道大会英雄_行数_1"]
				local 武道大会英雄_个数_1 = result["武道大会英雄_个数_1"]
				
				local 武道大会英雄_类型_2 = result["武道大会英雄_类型_2"]
				local 武道大会英雄_行数_2 = result["武道大会英雄_行数_2"]
				local 武道大会英雄_个数_2 = result["武道大会英雄_个数_2"]
				
				local 武道大会英雄_类型_3 = result["武道大会英雄_类型_3"]
				local 武道大会英雄_行数_3 = result["武道大会英雄_行数_3"]
				local 武道大会英雄_个数_3 = result["武道大会英雄_个数_3"]
				
				选择英雄类型(武道大会英雄_类型_1)
				mSleep(500)
				选择英雄角色(武道大会英雄_行数_1,武道大会英雄_个数_1)
				mSleep(1000)
				
				选择英雄类型(武道大会英雄_类型_2)
				mSleep(500)
				选择英雄角色(武道大会英雄_行数_2,武道大会英雄_个数_2)
				mSleep(1000)
				
				选择英雄类型(武道大会英雄_类型_3)
				mSleep(500)
				选择英雄角色(武道大会英雄_行数_3,武道大会英雄_个数_3)
				mSleep(1000)
				
				quickTap(1165,670)
				showHUD(id,"冒险模式==>等待进入战场",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
				----
				武道大会()
			end
		end
		
		--点击屏幕继续
		x, y = findColor({538, 617, 764, 676},
			"0|0|0xffffff,8|-8|0xffffff,9|-3|0xffffff,18|2|0xffffff,40|-8|0xffffff,40|-2|0xffffff,40|6|0xffffff,69|1|0xffffff,78|1|0xffffff,69|1|0xffffff",
			95, 0, 0, 0)
		if x > -1 then
			print("点击屏幕继续")
			quickTap(x,y)
			mSleep(4000)
		end
		
	end
end

function 进入战斗()
	--进入游戏战场
	while true do
		mSleep(200)
		
		showHUD(id,"人机对战中",12,"0xFFFFFFFF","0x40969696",0,254,685,685,34)      --显示HUD内容
		
		
		--点击屏幕继续
		x, y = findColor({549, 625, 752, 668},
			"0|0|0xffffff,32|5|0xffffff,53|6|0xffffff,123|2|0xffffff",
			95, 0, 0, 0)
		if x > -1 then
			quickTap(x,y)
		end
		
		--舞蹈大会成功嗝屁
		
		
		
		
		--结算界面的确定
		x, y = findColor({592, 643, 683, 688},
			"0|0|0x27739f,-7|-4|0x4f778b,-18|-8|0x45a8dc,-16|-15|0x6fb9db",
			90, 0, 0, 0)
		if x > -1 then
			quickTap( x,y)
		end
		
		--技能2升级
		x, y = findColor({955, 412, 977, 440},
			"0|0|0x18a0d3,0|-4|0x23abde,-5|-7|0x23a8df,2|-7|0x36a3d6",
			95, 0, 0, 0)
		if x > -1 then
			quickTap( x,y)
			
		end
		
		--技能3升级
		x, y = findColor({1083, 334, 1114, 364},
			"0|0|0xf1c81a,-7|-4|0xe8c216,5|-8|0xd2aa12,14|-3|0x8f700f",
			90, 0, 0, 0)
		if x > -1 then
			quickTap( x,y)
			
		end
		
		--技能1升级
		x, y = findColor({871, 546, 902, 577},
			"0|0|0x1fa3dc,3|1|0x22a6df,3|8|0x20a4e6",
			90, 0, 0, 0)
		if x > -1 then
			quickTap( x,y)
			
		end
		
		--人机失败的继续按钮
		x, y = findColor({592, 644, 689, 695},
			"0|0|0xd7e0e5,0|4|0x277ba5,2|-7|0x9cd6ef,7|-2|0x3399c8,16|4|0xffffff",
			95, 0, 0, 0)
		if x > -1 then
			quickTap( x,y)
			
		end
		
		--买装备
		x, y = findColor({99, 251, 180, 413},
			"0|0|0xfff44e,2|0|0xc28f41",
			90, 0, 0, 0)
		if x > -1 then
			quickTap( x,y)
			
		end
		
		--返回大厅
		x, y = findColor({513, 666, 616, 698},
			"0|0|0x07161e,5|-2|0xffffff,11|-2|0xf0f0f0,19|0|0x34a0d9",
			90, 0, 0, 0)
		if x > -1 then
			quickTap( x,y)
			break;
		end
		
		--胜利的第二次继续
		x, y = findColor({572, 645, 714, 693},
			"0|0|0x37a3dc,24|0|0xffffff,24|2|0xffffff,24|4|0xffffff,53|-7|0xffffff,65|-3|0x37a3d4",
			95, 0, 0, 0)
		if x > -1 then
			quickTap( x,y)
			
		end
		
		
		while true do
			mSleep(125)
			x, y = findColor({338, 90, 1080, 446},
				"0|0|0xda433f",
				98, 0, 0, 0)
			if x > -1 then
				quickTap(1177,616)
				quickTap(960,632)
				quickTap(1027,493)
				quickTap(1176,417)
			else
				break
			end
		end
		
		x, y = findColor({593, 640, 683, 693},
			"0|0|0x339fd8,7|-1|0x2d5d75,15|-2|0x195371,17|-3|0x339ac8",
			95, 0, 0, 0)
		if x > -1 then
			quickTap(x,y)
		end
		
		local offset = math.random(1,50)
		--判断英雄当前有没有被防御塔攻击
		x, y = findColor({234, 28, 923, 536},
			"0|0|0x752b02,0|-2|0x823702,1|-1|0x782e05",
			95, 0, 0, 0)
		if x > -1 then
			touchDown(1, 169,571)
			mSleep(50)
			touchMove(1, 169-50-offset,571+80+offset)
			mSleep(1500)
			touchUp(1, 169,571)
		else
			--被攻击，赶紧跑
			touchDown(1, 169,571)
			mSleep(50)
			touchMove(1, 169+50+offset,571-80-offset)
			mSleep(1500)
			touchUp(1, 169,571)
		end
		
		
		
	end
	return true
end

function 选择英雄类型(对战英雄_类型)
	if 对战英雄_类型 == "全部" then
		quickTap(92,42);
	elseif 对战英雄_类型== "坦克" then
		quickTap(227,44);
		
	elseif 对战英雄_类型== "战士" then
		quickTap(378,44);
		
	elseif 对战英雄_类型== "刺客" then
		quickTap(532,46);
		
	elseif 对战英雄_类型== "法师" then
		quickTap(674,40);
		
	elseif 对战英雄_类型== "射手" then
		quickTap(834,49);
		
	elseif 对战英雄_类型== "辅助" then
		quickTap(965,47);
		
	end
end

function 选择英雄角色(行,列)
	quickTap(67 + (tonumber(列)-1)*150,150+(tonumber(行)-1)*150)
	
end

ret,result = ui:show()
if ret == 1 then
	print(result)
	
	id = createHUD()     --创建一个HUD
	
	while true do
		mSleep(500)
		任务设置 = result["任务设置"]
		for v ,s in pairs(任务设置) do
			print(v)
			while true do
				
				--呵护双眼
				x, y = findColor({848, 476, 950, 525},
					"0|0|0xfea3c3,-8|-2|0xe780a2,8|-1|0xfae7ea,11|-4|0xb36c82,16|-12|0xd38596,27|-7|0xbf234b",
					95, 0, 0, 0)
				if x > -1 then
					quickTap(x,y)
				end
				
				
				if v == "战队签到" then
					showHUD(id,"战队签到==>检测主界面",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
					local 是否在主界面 = false;
					for i=0,20,1 do
						mSleep(100)
						
						x, y = findColor({977, 645, 1132, 718},
							"0|0|0xcfe4ff,-8|12|0xc4f1fd,1|12|0xc4f1fd,11|12|0xc4f1fd",
							95, 0, 0, 0)
						if x > -1 then
							是否在主界面 = true
							break;
							
						end
					end
					if 是否在主界面 == false then
						showHUD(id,"战队签到==>不在主界面",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
						
						toast("请退到主界面后再执行脚本！")
						lua_exit()
						
						break;
					end
					showHUD(id,"战队签到==>开始战队签到",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
					quickTap(755,686)
					
					for i=0,20,1 do
						mSleep(125)
						x, y = findColor({870, 82, 951, 188},
							"0|0|0xfc0e0f,-10|9|0x30b3ee,-13|3|0x1fa7e1",
							95, 0, 0, 0)
						if x > -1 then
							quickTap(x-30,y+20)
							
							while true do
								x, y = findColor({600, 502, 679, 541},
									"0|0|0xe59f26,16|3|0xffffff,17|2|0x35260c,20|2|0xffffff,26|2|0xffffff",
									95, 0, 0, 0)
								if x > -1 then
									showHUD(id,"战队签到==>领取战队奖励",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
									quickTap(x,y)
									mSleep(500)
									break
								end
							end
							break
						end
					end
					
					
					--回到主界面
					mSleep(500)
					quickTap(71,40)
					break
					
					
				elseif v == "武道大会测试" then
					武道大会()
				elseif v ==  "人机对战" then
					showHUD(id,"人机对战==>检测主界面",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
					mSleep(1500)
					local 是否在主界面 = false;
					print("人机对战—检测主界面")
					for i=0,20,1 do
						mSleep(100)
						x, y = findColor({977, 645, 1132, 718},
							"0|0|0xcfe4ff,-8|12|0xc4f1fd,1|12|0xc4f1fd,11|12|0xc4f1fd",
							95, 0, 0, 0)
						if x > -1 then
							print("人机对战—检测到界面")
							
							是否在主界面 = true
							break;
							
						end
					end
					if 是否在主界面 == false then
						showHUD(id,"人机对战==>不在主界面",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
						print("人机对战—不在主界面")
						
						toast("请退到主界面后再执行脚本！")
						lua_exit()
						break;
					end
					
					quickTap(321,348)
					mSleep(1000)
					quickTap(1059,236)
					mSleep(1000)
					quickTap(271,364)
					mSleep(200)
					quickTap(268,439)
					mSleep(1000)
					quickTap(698,606)
					showHUD(id,"人机对战==>开始匹配",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
					print("人机对战—等待匹配")
					
					while true do
						showHUD(id,"人机对战==>匹配中",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
						
						x, y = findColor({556, 540, 702, 586},
							"0|0|0x825f43,-5|-4|0xe59f28,-9|-6|0xffffff,21|-4|0xffffff",
							95, 0, 0, 0)
						if x > -1 then
							showHUD(id,"人机对战==>匹配到队友，开始游戏",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
							print("匹配到队友，开始游戏")
							
							quickTap(x,y)
							mSleep(1000)
							break
						end
					end
					--查找英雄选择界面
					showHUD(id,"人机对战==>游戏加载中",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
					print("游戏加载中")
					while true do
						x, y = findColor({28, 11, 110, 66},
							"0|0|0x1591ba,1|-1|0x1591ba,4|-1|0xffffff,7|-2|0x1488ae,9|-5|0xffffff",
							95, 0, 0, 0)
						if x > -1 then
							showHUD(id,"人机对战==>进入英雄选择界面",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
							
							quickTap(305,365) --展开英雄
							mSleep(1500)
							
							local 人机对战英雄_类型 = result["人机对战英雄_类型_1"]
							local 人机对战英雄_行数 = result["人机对战英雄_行数_1"]
							local 人机对战英雄_个数 = result["人机对战英雄_个数_1"]
							选择英雄类型(人机对战英雄_类型)
							mSleep(500)
							选择英雄角色(人机对战英雄_行数,人机对战英雄_个数)
							mSleep(1500)
							quickTap(1165,670)
							showHUD(id,"人机对战==>英雄已经确认，等待进入战场",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
							break
						end
					end
					--结束了才跳出
					
					--判断英雄是否进入战场
					while true do
						mSleep(200)
						showHUD(id,"人机对战==>判断是否进入战场 ",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
						
						x, y = findColor({20, 262, 84, 315},
							"0|0|0xf1bf33,11|8|0xf5c448,21|0|0xf1bf33,11|-22|0xf1e99e",
							95, 0, 0, 0)
						if x > -1 then
							break
						end
					end
					
					
					local 战斗结果  = 进入战斗()
					if 战斗结果 then
						break
					end
					
					
				elseif v ==  "好友金币" then
					mSleep(1000)
					showHUD(id,"好友金币==>检测主界面",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
					local 是否在主界面 = false;
					for i=0,20,1 do
						mSleep(100)
						
						x, y = findColor({977, 645, 1132, 718},
							"0|0|0xcfe4ff,-8|12|0xc4f1fd,1|12|0xc4f1fd,11|12|0xc4f1fd",
							95, 0, 0, 0)
						if x > -1 then
							是否在主界面 = true
							break;
							
						end
					end
					if 是否在主界面 == false then
						showHUD(id,"好友金币==>不在主界面",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
						
						toast("请退到主界面后再执行脚本！")
						lua_exit()
						
						break;
					end
					
					quickTap(1006,34)
					mSleep(500)
					local 金币是否满了 = false
					for i = 0,40,1 do
						--查找金币图标
						mSleep(125)
						point = findColors({1185, 147, 1272, 618}, "0|0|0xfff4a6",95, 0, 0, 0)
						if #point ~= 0 then
							showHUD(id,"好友金币==>开始赠送金币",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
							local existCoins = {}
							for v,s in pairs(point) do
								mSleep(125)
								local prePoint = point[v-1]
								local currPoint = s;
								
								
								
								if prePoint == nil then
									prePoint = s
									table.insert(existCoins,prePoint)
									
								end
								
								local i = 0
								for v,s in pairs(existCoins) do
									if tonumber(currPoint["y"]) - tonumber(s["y"]) > 50 then
										i = i+1
									end
								end
								
								if i == #existCoins then
									table.insert(existCoins,currPoint)
								end
							end
							
							print(existCoins)
							for v,s in pairs(existCoins) do
								mSleep(1000)
								quickTap(s["x"],s["y"])
								mSleep(100)
								
								--查找赠送金币是否已经满了
								for i =0,10,1 do
									mSleep(125)
									x, y = findColor({511, 344, 767, 383},
										"0|0|0x0e1322,6|-2|0xcecfe1,14|5|0xcccddf,30|-2|0xa5a6b8,46|-10|0x0e1321,46|-13|0xcecfe1,65|-4|0x686b7c,69|-9|0xcdcee0,159|-8|0xcdcee0,163|-4|0xbdbed0",
										95, 0, 0, 0)
									if x > -1 then
										--已赠送满
										showHUD(id,"好友金币==>今日金币赠送达到最大值",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
										金币是否满了 = true
										print("金币已满")
										break
									end
								end
								
								if  金币是否满了 then
									print("跳出赠送循环")
									break
								end
								
								--下次吧
								for i = 0,40,1 do
									mSleep(500)
									x, y = findColor({465, 467, 570, 510},
										"0|0|0x339ed8,12|-2|0xffffff,7|4|0x0c2635,24|-2|0x37a3d4",
										95, 0, 0, 0)
									if x > -1 then
										print("点击下次吧按钮")
										
										quickTap(x,y)
										break;
									end
								end
							end
							
							if 金币是否满了  then
								print("跳出20次查找金币的循环")
								break
							end
							print("第一页点完，开始滑动")
							swip(1088,545,1088,217)
							touchUp(1,1088,217)
							
							print("滑动结束")
							mSleep(1000)
						else
							print("没找到送金币的,开始滑动")
							mSleep(300)
							touchUp(1,1088,217)
							mSleep(125)
							swip(1088,545,1088,217)
							print("滑动结束")
						end
					end
					if 金币是否满了  then
						print("金币满了")
						
						mSleep(500)
						quickTap(71,40)
						break
					else
						print("循环40次也没送满")
						showHUD(id,"好友金币==>多加点同平台的好友吧，大兄弟",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
						
						--40次也没送满
						mSleep(500)
						quickTap(71,40)
						break
					end
				elseif v ==  "冒险模式" then
					showHUD(id,"冒险模式==>检测主界面",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
					mSleep(1500)
					local 是否在主界面 = false;
					for i=0,20,1 do
						mSleep(100)
						x, y = findColor({977, 645, 1132, 718},
							"0|0|0xcfe4ff,-8|12|0xc4f1fd,1|12|0xc4f1fd,11|12|0xc4f1fd",
							95, 0, 0, 0)
						if x > -1 then
							是否在主界面 = true
							break;
							
						end
					end
					if 是否在主界面 == false then
						showHUD(id,"冒险模式==>不在主界面",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
						
						toast("请退到主界面后再执行脚本！")
						lua_exit()
						break;
					end
					
					quickTap(1092,493)
					mSleep(1000)
					模式选择 = result["模式选择"]
					for v, s in pairs(模式选择) do
						print(v)
						while true do
							if v == "武道大会" then
								quickTap(232,362)
								mSleep(500)
								
								--如果不在冷却中就开始挑战
								showHUD(id,"冒险模式==>判断是否可以挑战",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
								
								local 是否弹出挑战按钮 = false
								for i=0,20,1 do
									mSleep(125)
									x, y = findColor({531, 520, 1120, 580},
										"0|0|0xe8a21d,16|-6|0xeba81d,18|21|0xe6961d,52|8|0xe69619",
										95, 0, 0, 0)
									if x > -1 then
										--查找到挑战按钮
										showHUD(id,"冒险模式==>开始挑战",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
										
										quickTap(x,y)
										break
									end
								end
								
								
								
								for i=0,20,1 do
									--点击挑战按钮
									mSleep(125)
									x, y = findColor({743, 233, 990, 339},
										"0|0|0xe6a229,8|1|0xffffff,19|0|0xffffff,24|0|0xffffff",
										95, 0, 0, 0)
									if x > -1 then
										是否弹出挑战按钮 = true
										quickTap(x,y)
										break
									end
								end
								
								--冷却或者挑战完了
								if 是否弹出挑战按钮 == false then
									showHUD(id,"冒险模式==>暂时不能挑战，返回",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
									
									mSleep(500)
									quickTap(71,40)
									break
								end
								mSleep(1000)
								--先清空所以上阵英雄
								showHUD(id,"冒险模式==>检测并删除已上阵英雄",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
								
								for i=0,10,1 do
									mSleep(125)
									x, y = findColor({1099, 48, 1249, 560},
										"0|0|0xfeffff,1|-8|0x9e0e25,0|9|0x7f0816,-10|0|0x8b0b1c,10|-1|0x8d0c1e",
										95, 0, 0, 0)
									if x > -1 then
										quickTap(x,y)
										mSleep(500)
									end
								end
								
								--按用户配置选择上阵英雄
								showHUD(id,"冒险模式==>武道大会英雄选择",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
								mSleep(1000)
								quickTap(305,365) --展开英雄
								mSleep(1500)
								local 武道大会英雄_类型_1 = result["武道大会英雄_类型_1"]
								local 武道大会英雄_行数_1 = result["武道大会英雄_行数_1"]
								local 武道大会英雄_个数_1 = result["武道大会英雄_个数_1"]
								
								local 武道大会英雄_类型_2 = result["武道大会英雄_类型_2"]
								local 武道大会英雄_行数_2 = result["武道大会英雄_行数_2"]
								local 武道大会英雄_个数_2 = result["武道大会英雄_个数_2"]
								
								local 武道大会英雄_类型_3 = result["武道大会英雄_类型_3"]
								local 武道大会英雄_行数_3 = result["武道大会英雄_行数_3"]
								local 武道大会英雄_个数_3 = result["武道大会英雄_个数_3"]
								
								选择英雄类型(武道大会英雄_类型_1)
								mSleep(500)
								选择英雄角色(武道大会英雄_行数_1,武道大会英雄_个数_1)
								mSleep(1000)
								
								选择英雄类型(武道大会英雄_类型_2)
								mSleep(500)
								选择英雄角色(武道大会英雄_行数_2,武道大会英雄_个数_2)
								mSleep(1000)
								
								选择英雄类型(武道大会英雄_类型_3)
								mSleep(500)
								选择英雄角色(武道大会英雄_行数_3,武道大会英雄_个数_3)
								mSleep(1000)
								
								quickTap(1165,670)
								showHUD(id,"冒险模式==>等待进入战场",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
								----
								武道大会()
							elseif v == "六国远征" then
								print("六国远征")
								showHUD(id,"六国远征==>判断当前关卡",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
								mSleep(2000)
								quickTap(1039,350)
								mSleep(1500)
								
								六国远征处理()
							elseif v == "挑战" then
								showHUD(id,"冒险模式==>判断当前界面",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
								local 是否在主界面 = false;
								for i=0,20,1 do
									mSleep(100)
									x, y = findColor({987, 651, 1118, 711},
										"0|0|0xacdff2,3|-3|0x305873,6|-3|0xbbebf9",
										95, 0, 0, 0)
									if x > -1 then
										是否在主界面 = true
										break;
										
									end
								end
								if 是否在主界面 == false then
									showHUD(id,"冒险模式==>进入冒险挑战",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
									mSleep(1500)
									quickTap(637,356)
								else
									quickTap(1039,474)
									mSleep(1500)
									quickTap(637,356)
									
								end
								
								mSleep(500)
								showHUD(id,"冒险模式==>选择挑战关卡",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
								
								local 挑战关卡 = result["挑战关卡"]
								local 挑战难度 = result["挑战难度"]
								if 挑战关卡 == "魔女回忆" then
									quickTap(300,208)
								elseif 挑战关卡 == "通天塔" then
									quickTap(312,393)
								end
								mSleep(1000)
								quickTap(762,303)
								mSleep(500)
								
								showHUD(id,"冒险模式==>选择挑战难度",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
								if  挑战难度 =="普通" then
									quickTap(1076,182)
								elseif 挑战难度 == "精英" then
									quickTap(1072,323)
								elseif 挑战难度 == "大师" then
									quickTap(1076,460)
								end
								mSleep(1000)
								quickTap(1078,653)
								
								while true do
									--更换阵容
									x, y = findColor({655, 576, 842, 637},
										"0|0|0x3890cc,8|-1|0xffffff,17|-1|0xffffff",
										95, 0, 0, 0)
									if x > -1 then
										quickTap(x,y)
										break
									end
								end
								
								--先清空所以上阵英雄
								showHUD(id,"冒险模式==>检测并删除已上阵英雄",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
								
								for i=0,10,1 do
									mSleep(125)
									x, y = findColor({1099, 48, 1249, 560},
										"0|0|0xfeffff,1|-8|0x9e0e25,0|9|0x7f0816,-10|0|0x8b0b1c,10|-1|0x8d0c1e",
										95, 0, 0, 0)
									if x > -1 then
										quickTap(x,y)
										mSleep(500)
									end
								end
								
								mSleep(1000)
								quickTap(305,365) --展开英雄
								mSleep(1500)
								
								
								--选择英雄
								local 挑战英雄_类型_1 = result["挑战英雄_类型_1"]
								local 挑战英雄_行数_1 = result["挑战英雄_行数_1"]
								local 挑战英雄_个数_1 = result["挑战英雄_个数_1"]
								
								local 挑战英雄_类型_2 = result["挑战英雄_类型_2"]
								local 挑战英雄_行数_2 = result["挑战英雄_行数_2"]
								local 挑战英雄_个数_2 = result["挑战英雄_个数_2"]
								
								local 挑战英雄_类型_3 = result["挑战英雄_类型_3"]
								local 挑战英雄_行数_3 = result["挑战英雄_行数_3"]
								local 挑战英雄_个数_3 = result["挑战英雄_个数_3"]
								
								选择英雄类型(挑战英雄_类型_1)
								mSleep(500)
								选择英雄角色(挑战英雄_行数_1,挑战英雄_个数_1)
								mSleep(1000)
								
								选择英雄类型(挑战英雄_类型_2)
								mSleep(500)
								选择英雄角色(挑战英雄_行数_2,挑战英雄_个数_2)
								mSleep(1000)
								
								选择英雄类型(挑战英雄_类型_3)
								mSleep(500)
								选择英雄角色(挑战英雄_行数_3,挑战英雄_个数_3)
								mSleep(1000)
								
								quickTap(1165,670)
								showHUD(id,"冒险模式==>挑战开始",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
								----
								进入挑战冒险()
								
							end
							
							break
						end
						
						
						
					end
					break
				elseif v ==  "任务奖励" then
					break
				elseif v ==  "铭文抽奖" then
					showHUD(id,"铭文抽奖==>检测主界面",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
					mSleep(1500)
					local 是否在主界面 = false;
					for i=0,20,1 do
						mSleep(100)
						x, y = findColor({977, 645, 1132, 718},
							"0|0|0xcfe4ff,-8|12|0xc4f1fd,1|12|0xc4f1fd,11|12|0xc4f1fd",
							95, 0, 0, 0)
						if x > -1 then
							是否在主界面 = true
							break;
							
						end
					end
					if 是否在主界面 == false then
						showHUD(id,"铭文抽奖==>不在主界面",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
						
						toast("请退到主界面后再执行脚本！")
						lua_exit()
						break;
					end
					
					quickTap(232,680)
					mSleep(1000)
					quickTap(60,390);
					mSleep(1000)
					showHUD(id,"铭文抽奖==>检测是否有免费铭文可以抽",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
					
					for i=0,20,1 do
						x, y = findColor({836, 666, 881, 695},
							"0|0|0xf4262e,-2|1|0xfa1c24,-3|-2|0xf42e36,0|-4|0xf2343e,5|1|0xfa1c24",
							95, 0, 0, 0)
						if x > -1 then
							showHUD(id,"铭文抽奖==>检测到免费抽奖机会",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
							
							quickTap(x,y)
							mSleep(5000)
							showHUD(id,"铭文抽奖==>抽奖中，请稍候",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
							
							for i=0,20,1 do
								mSleep(200)
								x, y = findColor({587, 477, 697, 520},
									"0|0|0x359fd7,8|0|0xffffff,10|-1|0x8c8c8c,12|-2|0x99c5da,15|-1|0x040404,26|-6|0xa1a1a1",
									95, 0, 0, 0)
								if x > -1 then
									showHUD(id,"铭文抽奖==>领取铭文",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
									quickTap(x,y)
									break;
								end
							end
							
							for i=0,20,1 do
								mSleep(200)
								x, y = findColor({587, 477, 697, 520},
									"0|0|0x359fd7,8|0|0xffffff,10|-1|0x8c8c8c,12|-2|0x99c5da,15|-1|0x040404,26|-6|0xa1a1a1",
									95, 0, 0, 0)
								if x > -1 then
									showHUD(id,"铭文抽奖==>领取铭文",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
									quickTap(x,y)
									break;
								end
							end
							
							
							break
						end
					end
					
					
					
					--回到主界面
					--回到主界面
					mSleep(1000)
					quickTap(71,40)
					break;
					
				elseif v ==  "邮件奖励" then
					showHUD(id,"邮件奖励==>检测主界面",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
					mSleep(1500)
					local 是否在主界面 = false;
					for i=0,20,1 do
						mSleep(100)
						x, y = findColor({977, 645, 1132, 718},
							"0|0|0xcfe4ff,-8|12|0xc4f1fd,1|12|0xc4f1fd,11|12|0xc4f1fd",
							95, 0, 0, 0)
						if x > -1 then
							是否在主界面 = true
							break;
							
						end
					end
					if 是否在主界面 == false then
						showHUD(id,"邮件奖励==>不在主界面",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
						
						toast("请退到主界面后再执行脚本！")
						lua_exit()
						break;
					end
					
					mSleep(500)
					quickTap(1060,30)
					mSleep(1000)
					showHUD(id,"邮件奖励==>检测好友是否赠送金币",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
					
					quickTap(61,144)
					for i=0,20,1 do
						mSleep(100)
						--好友送的金币 ，快速领取
						x, y = findColor({1055, 624, 1259, 713},
							"0|0|0xffffff,12|-5|0xffffff,12|8|0xffffff,23|-8|0xe6a42d,44|6|0xffffff,63|21|0xe89d1f",
							95, 0, 0, 0)
						
						if x > -1 then
							--找到快速领取
							quickTap(x,y)
							mSleep(100)
							
							--判断今天是不是已经领取了五位好友的金币
							local 金币是否已经领满  = false
							for i=0,20,1 do
								mSleep(10)
								x, y = findColor({580, 361, 695, 395},
									"0|0|0x0d1322,12|0|0x0d1322,22|0|0x0d1322",
									95, 0, 0, 0)
								if x > -1 then
									--回到主界面
									金币是否已经领满 = true;
									break
								end
							end
							
							if 金币是否已经领满 then
								break
							end
							
							
							--点击下次吧按钮
							for i=0,40,1 do
								mSleep(300)
								x, y = findColor({442, 466, 575, 508},
									"0|0|0x349dd7,4|-2|0xa0d2ed,7|-2|0xffffff,9|-3|0x0d2735,10|-2|0x2e91c5",
									95, 1, 1, 0)
								if x > -1 then
									showHUD(id,"邮件奖励==>赠送好友金币",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
									quickTap(x,y)
									break
								end
							end
							
							--点击金币确定
							for i=0,40,1 do
								mSleep(300)
								x, y = findColor({589, 478, 703, 523},
									"0|0|0x359ed6,6|-2|0xf2f7fa,14|-4|0xffffff,15|-2|0x040404,16|-2|0x3891bc",
									95, 1, 1, 0)
								if x > -1 then
									showHUD(id,"邮件奖励==>领取好友赠送的金币",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
									
									quickTap(x,y)
									break
								end
							end
							
							break;
						end
					end
					
					--好友金币领取完，开始领取系统邮件
					quickTap(64,230)
					showHUD(id,"邮件奖励==>检测系统邮件",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
					for i=0,20,1 do
						mSleep(200)
						x, y = findColor({1092, 638, 1218, 686},
							"0|0|0xe5e5e4,-1|1|0x150e03,3|0|0xffffff,8|1|0x150f04,10|2|0xcc8c21",
							95, 1, 1, 0)
						if x > -1 then
							showHUD(id,"邮件奖励==>快速领取",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
							quickTap(x,y)
							--检测确定按钮
							for i=0,40,1 do
								mSleep(125)
								x, y = findColor({557, 478, 707, 523},
									"0|0|0x349cd6,7|-3|0x8c8c8c,17|-10|0x1c1c1c,16|-4|0xffffff",
									95, 1, 1, 0)
								if x > -1 then
									showHUD(id,"邮件奖励==>领取奖励",12,"0xFFFFFFFF","0x40969696",0,250,0,500,32)      --显示HUD内容
									quickTap(x,y)
								end
							end
							break
						end
					end
					
					--点击左上角返回
					--回到主界面
					mSleep(1000)
					quickTap(71,40)
					break
				end
				
			end
			
			
		end
	end
else
	toast("退出脚本")
	mSleep(1000)
	lua_exit()
end